#include "continueRecharge.h"
#include "scene_logic.h"

CContinueRecharge::CContinueRecharge() : _fRechargeTotalQuantity( 0.0 ), _rsRewardState(), _iPlayerId( 0 )
{
}

CContinueRecharge::~CContinueRecharge()
{
}

void CContinueRecharge::Init()
{
	_fRechargeTotalQuantity = 0.0;
	_rsRewardState.SetId( 0 );
	_rsRewardState.SetState( 0 );
	_iPlayerId = 0;
}

void CContinueRecharge::SetPlayerId( int iPlayerId )
{
	_iPlayerId = iPlayerId;
}

int CContinueRecharge::GetPlayerId()
{
	return _iPlayerId;
}

void CContinueRecharge::SetRechargeTotalQuantity( float fQuantity )
{
	_fRechargeTotalQuantity = fQuantity;
}

float CContinueRecharge::GetRechargeTotalQuantity()
{
	return _fRechargeTotalQuantity;
}


void CContinueRecharge::SetRewardState( RewardState const & rs )
{
	_rsRewardState = rs;
}

RewardState CContinueRecharge::GetRewardState()
{
	return _rsRewardState;
}

void CContinueRecharge::ReadFromJson( Json::Value const & jsv )
{
	if ( jsv.isMember( "rechargeTotalQuantity" ) )
		SetRechargeTotalQuantity( jsv[ "rechargeTotalQuantity" ].asDouble() );

	if ( jsv.isMember( "rewardState" ) )
	{
		/*
			std::string strjs = jsv[ "rewardState" ].asString();
			Json::Value js;
			JsonReader( strjs, js )
		*/

		Json::Value js = jsv[ "rewardState" ];
		std::string strJs = JsonWriter( js );
		for (int32_t i = 0; i < js.size(); ++i)
		{
			Json::Value oneJs = js[ i ];
			_rsRewardState.SetId( oneJs[ "id" ].asInt() );
			_rsRewardState.SetState( oneJs[ "st" ].asInt() );
		}
	}
}

void CContinueRecharge::ReadFromPtree ( ptree && ptreeTmp )
{
	auto dblTQ = ptreeTmp.get< double > ( "continueRecharge.rechargeTotalQuantity", 0 );
	SetRechargeTotalQuantity ( dblTQ );
	for( auto & v : ptreeTmp.get_child ( "continueRecharge.rewardState" ) )
	{
		_rsRewardState.SetId ( v.second.get< int > ( "id", 0 ) );
		_rsRewardState.SetState ( v.second.get< int > ( "st", -1 ) );
	}
}

void CContinueRecharge::Write2Json( Json::Value & jsv )
{
	jsv[ "rechargeTotalQuantity" ] = GetRechargeTotalQuantity();
	jsv[ "rewardState" ][ "id" ] = GetRewardState().GetId();
	jsv[ "rewardState" ][ "st" ] = GetRewardState().GetState();
}